
close all;
clear;
clc;

range = qq(2000,1):qq(2015,4);
d.x = hpf2(cumsum(tseries(range,@randn)));
d.y = hpf2(cumsum(tseries(range,@randn)));
d.z = hpf2(cumsum(tseries(range,@randn)));
d.a = hpf2(cumsum(tseries(range,@randn)));
d.b = hpf2(cumsum(tseries(range,@randn)));

% dbplot(d,range,fieldnames(d),'tight=',true,'zeroline=',true);

D.A = d;
D.B = d;

vp = VAR({'x','y','z'}, ...
    'exogenous=',{'a','b'}, ...
    'groups=',{'A','B'});

vp = xasymptote(vp,0);

v = VAR({'x','y','z'}, ...
    'exogenous=',{'a','b'});

w = VAR({'x','y','z'});

JJ = nan(3,2);
JJ(1) = 0;
[vp,vpd] = estimate(vp,D,range,'order=',2,'J=',JJ);
vp = xasymptote(vp,0);

[v,vd] = estimate(v,d,range,'order=',2);
v = xasymptote(v,0);

[w,wd] = estimate(w,d,range,'order=',2);


%%

sp = simulate(vp,vpd,range(3):range(end));
s = simulate(w,wd,range(3):range(end));
c = simulate(w,wd,range(3):range(end),'contributions=',true);

%%

frange = range(end-10):range(end);
s = simulate(v,d,frange);
f = forecast(v,d,frange);

%%

xi = instrument(v,'i','x+y');

c = struct();
c.i = tseries(frange(1:2),0);

f = forecast(v,d,frange);
fi = forecast(xi,d,frange,c);


